package com.yue.authorization.resource;

import com.yue.authorization.common.Constant;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletContext;
import java.util.Calendar;
import java.util.Date;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/7/22<br/>
 *
 * @author QiuYang
 */
@Controller
@RequestMapping("/authentication")
public class AuthenticaitonResource {
    private final static Log logger = LogFactory.getLog(AuthenticaitonResource.class);

    @Autowired
    ServletContext servletContext;

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public String authenticateUser(@RequestParam(value = "username", required = true) String username,
                                   @RequestParam(value = "password", required = true) String password){
        Date expriy = getExpiryDate(Constant.EXPRIYDATE);

        return null;
    }

    private Date getExpiryDate(int minutes){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MINUTE, minutes);

        return calendar.getTime();
    }
}
